package com.purong.purong.activity;

import android.graphics.Color;
import android.os.Build;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.adapter.LoginPagerAdapter;
import com.purong.purong.fragment.LoginPwdFragment;
import com.purong.purong.fragment.LoginSmsFragment;
import com.purong.purong.util.CommonUtil;
import com.purong.purong.util.StatusBarUtil;

import java.util.ArrayList;

/**
 * Created by zengwenjie on 2017/11/30.
 */
public class LoginActivity extends BaseActivity {
    private ImageView statusBar;
    private ImageView pwdArrow,smsArrow;
    private TextView pwdTag,smsTag;
    private ViewPager mViewPager;
    private LoginPagerAdapter mAdapter;
    private ArrayList<Fragment> fragmentList=new ArrayList<>();
    @Override
    public int getRootViewId() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {
        StatusBarUtil.setStatusBarTran(this);
        statusBar = (ImageView)findViewById(R.id.status_bar);
        pwdTag=(TextView)findViewById(R.id.pwd_tag);
        smsTag=(TextView)findViewById(R.id.sms_tag);
        pwdArrow=(ImageView) findViewById(R.id.pwd_arrow);
        smsArrow=(ImageView) findViewById(R.id.sms_arrow);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){
            statusBar.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));
        }else {
            statusBar.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, CommonUtil.getStatusBarHeight(this)));
        }
        findViewById(R.id.top_lay).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,(int)(CommonUtil.getScreenWidth(this)/1.752)));
        LoginPwdFragment pwdFragment=new LoginPwdFragment();
        fragmentList.add(pwdFragment);
        LoginSmsFragment smsFragment=new LoginSmsFragment();
        fragmentList.add(smsFragment);
        mViewPager=(ViewPager)findViewById(R.id.view_pager);
        mAdapter=new LoginPagerAdapter(getSupportFragmentManager(),fragmentList);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(2);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position==0){
                    pwdTag.setTextColor(Color.parseColor("#FFFFFFFF"));
                    pwdArrow.setVisibility(View.VISIBLE);
                    smsTag.setTextColor(Color.parseColor("#7FFFFFFF"));
                    smsArrow.setVisibility(View.INVISIBLE);

                }else if (position==1){
                    pwdTag.setTextColor(Color.parseColor("#7FFFFFFF"));
                    smsArrow.setVisibility(View.VISIBLE);
                    smsTag.setTextColor(Color.parseColor("#FFFFFFFF"));
                    pwdArrow.setVisibility(View.INVISIBLE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void initData() {
    }
    public void onClick(View v){
        switch (v.getId()){
            case R.id.close:
                this.finish();
                break;
            case R.id.pwd_lay:
                mViewPager.setCurrentItem(0);
                break;
            case R.id.sms_lay:
                mViewPager.setCurrentItem(1);
                break;
        }
    }
}
